package com.zhentao.controller;

import com.zhentao.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户Controller
 */
@RestController
@RequestMapping("/produce/user")
public class UserController {
    
    @Autowired
    private com.zhentao.service.UserService userService;
    
    /**
     * 获取所有用户
     */
    @GetMapping("/getAll")
    public Map<String, Object> getAll() {
        List<User> list = userService.list();
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("message", "查询成功");
        response.put("data", list);
        
        return response;
    }
    
    /**
     * 分页查询用户
     */
    @GetMapping("/list")
    public Map<String, Object> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String name) {
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("message", "查询成功");
        response.put("data", userService.list());
        
        return response;
    }
    
    /**
     * 根据ID查询用户
     */
    @GetMapping("/getById/{id}")
    public Map<String, Object> getById(@PathVariable Long id) {
        User user = userService.getById(id);
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("message", "查询成功");
        response.put("data", user);
        
        return response;
    }
} 